import socket
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(24,GPIO.OUT)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host_addr=('192.168.10.174',80)
sock.bind(host_addr)
sock.listen(5)
while True:
    connection,address = sock.accept()
    try:
        connection.settimeout(5)
        buf = connection.recv(1024)
        if buf == '1':
            connection.send('led is turn on!')
            GPIO.output(24,True)
        if buf == '0':
            connection.send('led is turn off!')
            GPIO.output(24,False)
    except socket.timeout:
        print 'time out'
    connection.close()


